<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input
        v-model="listQuery.condition.role_name"
        placeholder="名称"
        style="width: 200px"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />

      <el-select
        v-model="listQuery.condition.status"
        placeholder="状态"
        clearable
        class="filter-item"
        style="width: 130px"
      >
        <el-option
          v-for="item in UserStatusOptions"
          :key="item.key"
          :label="item.display_name"
          :value="item.id"
        />
      </el-select>

      <el-button
        v-waves
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="handleFilter"
      >
        搜索
      </el-button>
      <el-button
        class="filter-item"
        style="margin-left: 10px"
        type="primary"
        icon="el-icon-edit"
        @click="handleCreate"
        v-purview-check="{
          modules: 'sys_account',
          resources: 'sys_account',
          operates: 'add',
        }"
      >
        添加
      </el-button>
    </div>

    <div class="grid-content bg-purple">
      <el-table
        :data="BaseDataList"
        style="width: 100%; margin-top: 30px"
        border
      >
         <el-table-column align="center" label="ID" width="150">
              <template slot-scope="scope">
                {{ scope.row.id }}
              </template>
            </el-table-column> 
        <el-table-column align="center" label="角色名称" >
          <template slot-scope="scope">
            {{ scope.row.role_name }}
          </template>
        </el-table-column>
          <el-table-column align="center" label="状态" width="150">
          <template slot-scope="scope">
            {{ scope.row.role_name }}
          </template>
        </el-table-column>

         <el-table-column align="center" label="操作">
              <template slot-scope="scope">
                <el-button
                  type="primary"
                  size="small"
                  @click="handleEdit(scope)"
                  v-purview-check="{
                    modules: 'sys_roles',
                    resources: 'sys_roles',
                    operates: 'modify',
                  }"
                >
                  修改
                </el-button>

                <el-button
                  type="primary"
                  size="small"
                  @click="handleEdit(scope)"
                  v-purview-check="{
                    modules: 'sys_roles',
                    resources: 'sys_roles',
                    operates: 'modify',
                  }"
                >
                  详细设置
                </el-button>
                <el-button
                  type="danger"
                  size="small"
                  @click="handleDelete(scope)"
                  v-purview-check="{
                    modules: 'sys_roles',
                    resources: 'sys_roles',
                    operates: 'delete',
                  }"
                  >删除</el-button
                >
              </template>
            </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="listQuery.page_index"
        :limit.sync="listQuery.page_size"
        @pagination="getList"
      />
    </div>
  </div>
</template>
<script>
import waves from "@/directive/waves"; // waves directive
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
import Constants from "@/utils/constants";
import { GetRoleList } from "@/api/roles";

export default {
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      UserStatusOptions: [],
      AccountTypeOptions: [],
      listQuery: {
        page_size: 20,
        page_index: 1,
        condition: { status: "-1", role_name: "" },
      },
        total: 0,
        BaseDataList:[]
    };
  },
  mounted() {
      this.getList();
    this.UserStatusOptions = Constants.user_status;
    this.AccountTypeOptions = Constants.account_type;
  },
  methods: {
    handleNodeClick(data) {
      this.BaseDataList = [];
      this.listQuery.condition.account_type = data.id;
      this.total = 0;
      this.listQuery.page_index = 1;
      this.getList();
    },
    getList() {
      GetRoleList(this.listQuery).then((res) => {
        this.BaseDataList = res.data.list;
        this.total = res.data.total;
      });
    },
    handleFilter() {
      this.BaseDataList = [];
      this.total = 0;
      this.listQuery.page_index = 1;
      this.getList();
    },
    handleCreate() {},
    handleDownload() {},
    handleEdit() {},
    handleDelete() {},
  },
};
</script>